Passed
Pull Request — master (#30)
by lv
01:57
created

db.js ➔ ???   A

Complexity

Conditions 1
Paths 5

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 1
c 0
b 0
f 0
nc 5
rs 10
nop 0
1
const Config = require('../../config/config')
2
const Knex = require('knex')
3
const Logger = require('../handlers/logger')
4
5
//db单例
6
class DB {
7
  constructor() {
8
    try {
9
      this.readMysql = Knex({
10
        client: 'mysql',
11
        connection: {
12
          host: Config.read_mysql.host,
13
          user: Config.read_mysql.user,
14
          password: Config.read_mysql.password,
15
          database: Config.read_mysql.database,
16
          charset: 'utf8mb4',
17
          collation: 'utf8mb4_unicode_ci'
18
        },
19
        pool: { min: Config.read_mysql.minConnection, max: Config.read_mysql.maxConnection }
20
      })
21
      Logger.getLogger('system').trace('readMysql init')
22
23
      this.writeMysql = Knex({
24
        client: 'mysql',
25
        connection: {
26
          host: Config.write_mysql.host,
27
          user: Config.write_mysql.user,
28
          password: Config.write_mysql.password,
29
          database: Config.write_mysql.database,
30
          charset: 'utf8mb4',
31
          collation: 'utf8mb4_unicode_ci'
32
        },
33
        pool: { min: Config.write_mysql.minConnection, max: Config.write_mysql.maxConnection }
34
      })
35
      Logger.getLogger('system').trace('writeMysql init')
36
    } catch (e) {
37
      console.log(e)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
38
    }
39
  }
40
}
41
42
module.exports = new DB()